package com.jeremyfeinstein.utils;

import java.util.ArrayList;
import java.util.List;

import android.text.TextUtils;

import com.jeremyfeinstein.gson.DepItem;
import com.jeremyfeinstein.gson.Info;
import com.jeremyfeinstein.gson.Location;
import com.jeremyfeinstein.gson.MeetingUser;
import com.jeremyfeinstein.gson.SendMessage;
import com.jeremyfeinstein.gson.User;
import com.jeremyfeinstein.gson.UserItem;

public class YCHSInstance {
	private User loginUser;
	private static YCHSInstance instance;
	private List<SendMessage> sendMessages;
	private List<MeetingUser> meetingUsers;
	private List<UserItem> userItems;
	private List<DepItem> depItems;
	private int mode;
	private String recorderId;
	private List<Location> locations;
	private List<Info> infos;

	private YCHSInstance() {
		sendMessages = new ArrayList<SendMessage>();
		setMeetingUsers(new ArrayList<MeetingUser>());
	}

	public static YCHSInstance getInstance() {
		if (instance == null) {
			instance = new YCHSInstance();
		}
		return instance;
	}

	public static void resetInstance() {
		instance = null;
	}

	public User getLoginUser() {
		return loginUser;
	}

	public void setLoginUser(User loginUser) {
		this.loginUser = loginUser;
	}

	public List<SendMessage> getSendMessages() {
		return sendMessages;
	}

	public void addSendMessages(SendMessage sendMessage) {
		for (SendMessage msg : this.sendMessages) {
			if (msg.getMEETING_ID().equalsIgnoreCase(
					sendMessage.getMEETING_ID())) {
				this.sendMessages.remove(msg);
			}
		}
		this.sendMessages.add(sendMessage);
	}

	/**
	 * @return the meetingUsers
	 */
	public List<MeetingUser> getMeetingUsers() {
		return meetingUsers;
	}

	/**
	 * @param meetingUsers
	 *            the meetingUsers to set
	 */
	public void setMeetingUsers(List<MeetingUser> meetingUsers) {
		this.meetingUsers = meetingUsers;
	}

	/**
	 * @return the selectUsers
	 */
	public List<UserItem> getUserItems() {
		return userItems;
	}

	/**
	 * @param selectUsers
	 *            the selectUsers to set
	 */
	public void setUserItems(List<UserItem> selectUsers) {
		this.userItems = selectUsers;
	}

//	/**
//	 * @return the depItems
//	 */
//	public List<DepItem> getDepItems() {
//		return depItems;
//	}
//
//	/**
//	 * @param depItems
//	 *            the depItems to set
//	 */
//	public void setDepItems(List<DepItem> depItems) {
//		this.depItems = depItems;
//	}

	public String getUserName(String userCode) {
		if (!TextUtils.isEmpty(userCode)) {
			for (UserItem item : userItems) {
				if (userCode.equalsIgnoreCase(item.getUser_code())) {
					return item.getUser_name();
				}
			}
		}
		return null;
	}

	public String getDeptName(String id) {
		if (!TextUtils.isEmpty(id)) {
			for (DepItem item : depItems) {
				if (id.equalsIgnoreCase(item.getID())) {
					return item.getDEP_NAME();
				}
			}
		}
		return null;
	}

	public int getMode() {
		return mode;
	}

	public void setMode(int mode) {
		this.mode = mode;
	}

	public String getRecorderId() {
		return recorderId;
	}

	public void setRecorderId(String recorderId) {
		this.recorderId = recorderId;
	}

	public List<Location> getLocations() {
		return locations;
	}

	public void setLocations(List<Location> locations) {
		this.locations = locations;
	}

	public List<Info> getInfos() {
		return infos;
	}

	public void setInfos(List<Info> infos) {
		this.infos = infos;
	}

}
